﻿
Partial Class App_esempio1
    Inherits MyUI.PageBaseApp

    Protected Sub Page_Load(sender As Object, e As System.EventArgs) Handles Me.Load



        If Not Me.Page.IsPostBack Then
            SetData()
        End If



    End Sub

    Private Sub SetData()




        UI.Grid.Bind(Me.GridView1, DB.TAB.User.ToList, {"ID"})

        Me.Rptpippo.DataSource = DB.TAB.User.ToList
        Me.Rptpippo.DataBind()


    End Sub

    Protected Sub GridView1_RowCancelingEdit(sender As Object, e As System.Web.UI.WebControls.GridViewCancelEditEventArgs) Handles GridView1.RowCancelingEdit

        Me.GridView1.EditIndex = -1
        SetData()

    End Sub

    Protected Sub GridView1_RowCommand(sender As Object, e As System.Web.UI.WebControls.GridViewCommandEventArgs) Handles GridView1.RowCommand


        If e.CommandName.ToUpper = "UPDATE" Then

            'Dim ct = e.CommandSource.DataItemContainer.DataItemIndex
            Dim ct = e.CommandSource.NamingContainer.RowIndex

            Dim id = sender.datakeys(ct).value
            Dim v = UI.Grid.GetTextBox(Me.GridView1, ct, "TxtName").Text

            'Dim ooo = UI.Controls.FindControl(Of TextBox)("pippo", Me.Page.Controls)


        End If


    End Sub

    Protected Sub GridView1_RowEditing(sender As Object, e As System.Web.UI.WebControls.GridViewEditEventArgs) Handles GridView1.RowEditing


        Me.GridView1.EditIndex = e.NewEditIndex

        SetData()

    End Sub

    Protected Sub GridView1_RowUpdating(sender As Object, e As System.Web.UI.WebControls.GridViewUpdateEventArgs) Handles GridView1.RowUpdating




        Dim u = DB.TAB.User.GetByPK(e.Keys("UserID"))
        u.Name = UI.Grid.GetTextBox(Me.GridView1, e.RowIndex, "TxtName").Text

        'u.save()

        DB.SubmitChanges()



        Me.GridView1.EditIndex = -1

        SetData()


    End Sub

    'Private Sub SetDataDB()
    '    Dim g = Me.GridLocations
    '    'Dim RecEditID As New List(Of Integer)
    '    'For ct As Integer = 0 To g.Rows.Count - 1
    '    '    RecEditID.Add(g.DataKeys(ct).Value)
    '    'Next

    '    Dim RecEditID = (From k In g.DataKeys Select k.valUe).ToList
    '    If RecEditID.Count > 0 Then

    '        Dim Records = CurrElab.TabElaborationLocSimulate.Where("ID", "in", RecEditID).ToList.ToDictionary(Function(o) o.ID)
    '        'Dim Records = CurrElab.TabElaborationLocSimulate.Where("ID", "in", RecEditID).ToDictionary(Of Integer)("ID")
    '        For ct As Integer = 0 To g.Rows.Count - 1

    '            Dim NewWeight = Utils.Conv.ToInt(UI.Grid.GetTextBox(g, ct, "TxtWeight").Text)
    '            'If CurrElab.CalibrateStatus = Geo.Elaborations.Calibrate.StatusType.CALIBRATE And Records(g.DataKeys(ct).Value).Weight <> NewWeight Then
    '            '    Records(g.DataKeys(ct).Value).CalibrateModifiedWeight = Records(g.DataKeys(ct).Value).Weight
    '            'End If
    '            Records(g.DataKeys(ct).Value).Weight = NewWeight
    '            Records(g.DataKeys(ct).Value).Performance = Utils.Conv.ToDouble(UI.Grid.GetTextBox(g, ct, "TxtPerformance").Text)
    '            Records(g.DataKeys(ct).Value).Selected = DB.ToBool(UI.Grid.GetCheckBox(g, ct, "ChkSelected").Checked)
    '            Records(g.DataKeys(ct).Value).CalibrateToDo = DB.ToBool(UI.Grid.GetCheckBox(g, ct, "ChkCalibrateToDo").Checked)
    '            Records(g.DataKeys(ct).Value).AreaMQ = Utils.Conv.ToDouble(UI.Grid.GetTextBox(g, ct, "TxtAreaMQ").Text)
    '            Records(g.DataKeys(ct).Value).Description = UI.Grid.GetTextBox(g, ct, "TxtDescription").Text

    '        Next

    '        DB.SubmitChanges()

    '    End If

    '    Me.SetDataLocation(True)

    'End Sub
End Class
